<include file="./VMSTpl/Admin/header.html" />
<div class="alert alert-info alert-dismissable" style="margin-top:-20px;{$txtBox}">
    <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
<strong>注意!</strong> 请在右上方的输入框输入需要修改信息对应的飞机号或者出厂号 </div>
<volist name="tips" id="vo">
  <div class="alert alert-warning alert-dismissable" style="margin-top:-20px;">
    <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
    <strong>注意!</strong> {$vo} </div>
</volist>
<div class="container">
  <h2>{$title}</h2>

  <volist name="data" id="vo">
    <form method="post" style="{$style}" onSubmit="return check();" action="__ROOT__/Admin/changePlane">
      <table class="table table-striped col-md-6 table-hover" style="margin-top:50px;">
        <tbody>
          <tr>
            <td>单位</td>
            <td><select name="unit" class="form-control" required>
                <volist name="unit" id="u">
                  <option value="{$u['id']}" {$u['state']}>{$u['id']}.{$u['name']}</option>
                </volist>
              </select></td>
          </tr>
          <tr>
            <td>飞机号码</td>
            <td><input name="no" class="form-control" value="{$vo['no']}" readonly = "readonly"></td>
          </tr>
          <tr>
            <td>翻修次数</td>
            <td><select name="revi" class="form-control" required>
                <volist name="revi" id="u">
                  <option value="{$u['id']}" {$u['state']}>{$u['id']}</option>
                </volist>
              </select></td></td>
          </tr>
          <tr>
            <td>出厂号码</td>
            <td><input name="man" class="form-control" value="{$vo['man']}" required></td>
          </tr>
          <tr>
            <td>进厂日期</td>
            <td><input name="in" class="form-control" value="{$vo['in']}" required></td>
          </tr>
        </tbody>
      </table>
      <div class="row col-md-offset-5">
          <button type="submit" class="btn btn-primary" style="{$style}">保存</button>
          <button type="button" class="btn btn-danger del" style="{$style}">删除</button>
          <a type="button" class="btn btn-default" href="__ROOT__/Admin/Index">返回</a>
      </div>
    </form>
  </volist>
</div>
<include file="./VMSTpl/Admin/tailer.html" /> 
<script>

	$("document").ready(function(){
		
		$(".del").click(function(){
			var no = $("input[name='no']").val();
			var target = $(this).parent().parent();
			if(confirm("确定要删除该记录！")){
				var url = "__ROOT__/Admin/delPlane?no="+no; 
				$.get(url, function(data) { 
					if(data=="1") { 
					alert("删除失败！"); 
					return; 
				}
				else if(data=="0"){
					alert("删除成功！"); 
					target.remove();
					$(".alert-info").show();
					window.location.href="__ROOT__/Admin/index";
				}
				
				})
			}
			
		})
	})
	
	function check(){
		var unit = $("select[name='unit']").val();
		var no = $("input[name='no']").val();
		var revi = $("select[name='revi']").val();
		var man = $("input[name='man']").val();
		var date = $("input[name='in']").val();
		var reg=/^\d{4}$/;
		if(!reg.test(no)){
			alert("飞机号码格式有误！");
			$("input[name='no']").focus();
			return false;
		}
		
		reg=/^\d{7}$/;
		if(!reg.test(man)){
			alert("出厂号码格式有误！");
			$("input[name='man']").focus();
			return false;
		}
		
		reg=/^(?:(?!0000)[0-9]{4}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-8])|(?:0[13-9]|1[0-2])-(?:29|30)|(?:0[13578]|1[02])-31)|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)-02-29)$/;
		if(!reg.test(date)){
			alert("日期格式有误！");
			$("input[name='date']").focus();
			return false;
		}
	}
</script>